import { createRouter, createWebHistory } from "vue-router";
import { h } from 'vue';

// 定义常量路由并导出
export const constantRouter = [
  {
    path: "/layout",
    component: () => import("../layouut/index.vue"),
    meta: {
      title: "",
      hidden: true, // 隐藏父路由，只显示子路由
      icon: "",
    },
    children: [
      {
        path: "/home",
        component: () => import("../views/home/index.vue"),
        meta: {
          title: "首页",
          hidden: false,
          icon: "HomeFilled",
        },
      },
    ],
  },
  {
    //登录
    path: "/login",
    name: "login",
    component: () => import("../views/login/index.vue"),
    meta: {
      title: "登录",
      hidden: true, //登录页不显示在菜单中
    },
  },
  {
    // 默认重定向到登录页
    path: "/",
    redirect: "/login",
    meta: {
      title: "登录",
      hidden: true, //登录页不显示在菜单中
    },
  },
  //数据大屏
  {
    path: "/screen",
    name: "screen",
    component: () => import("../views/screen/index.vue"),
    meta: {
      title: "数据大屏",
      hidden: false,
      icon: "platform",
    },
  },
  //权限管理
  {
    path: "/acl",
    name: "acl",
    component: () => import("../layouut/index.vue"),
    meta: {
      title: "管理",
      hidden: false,
      icon: "User",
    },
    redirect: "/acl/user",
    children: [
      {
        path: "/acl/user",
        name: "user",
        component: () => import("../views/acl/User/index.vue"),
        meta: {
          title: "用户管理",
          hidden: false,
          icon: "User",
        },
      },
      {
        path: "/acl/role",
        name: "role",
        component: () => import("../views/acl/Role/index.vue"),
        meta: {
          title: "角色管理",
          hidden: false,
          icon: "User",
        },
      },
      {
        path: "/acl/permission",
        name: "permission",
        component: () => import("../views/acl/permission/index.vue"),
        meta: {
          title: "权限管理",
          hidden: false,
          icon: "User",
        },
      },
    ],
  },
  //布局路由（作为父路由）

  //商品管理
  {
    path: "/product",
    name: "product",
    component: () => import("../layouut/index.vue"),
    meta: {
      title: "商品管理",
      hidden: false,
      icon: "goods",
    },
    redirect: "/product/Trademark",
    children: [
      {
        path: "/product/Trademark",
        name: "Trademark",
        component: () => import("../views/product/trademark/index.vue"),
        meta: {
          title: "商品品牌管理",
          icon: "ShoppingCartFull",
        },
      },
      {
        path: "/product/attr",
        name: "attr",
        component: () => import("../views/product/attr/index.vue"),
        meta: {
          title: "商品属性管理",
          icon: "ChromeFilled",
        },
      },
      {
        path: "/product/spu",
        name: "spu",
        component: () => import("../views/product/spu/index.vue"),
        meta: {
          title: "商品SPU管理",
          icon: "Orange",
        },
      },
      {
        path: "/product/Sku",
        name: "Sku",
        component: () => import("../views/product/sku/index.vue"),
        meta: {
          title: "商品SKU管理",
          icon: "Calendar",
        },
      },
    ],
  },
  //404
  {
    path: "/:pathMatch(.*)*",
    name: "404",
    component: () => import("../views/404/index.vue"),
    meta: {
      title: "404",
      hidden: true,
    },
  },
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: constantRouter, // 使用导出的常量路由
});
export default router;
